import { Global, Module } from '@nestjs/common';
import { DbService } from './db.service';
import {TypegooseModule} from  'nestjs-typegoose'
import { User } from './models/user.model';
import { Coures } from './models/course.model';
import { Episode } from './models/episode.model';

//导入模型 统一引用
const models = TypegooseModule.forFeature([
  User,
  Coures,
  Episode
])

//标记为全局
@Global()
@Module({
  imports:[
     //链接数据数据库
     TypegooseModule.forRoot("mongodb://localhost:27017/test", {
      useNewUrlParser: true,
      useUnifiedTopology:true,
      useCreateIndex:true,
      useFindAndModify:true
    }),
    models

  ],
  providers: [DbService],
  exports: [DbService,models],
})
export class DbModule {}
